package top.itaso.app.ui.wifi;

import android.net.wifi.ScanResult;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

import top.itaso.app.R;

/**
 * @Description:
 * @Author: dengfu.su
 * @CreateDate: 2022/1/5
 */
public class WifiScanResultAdapter extends RecyclerView.Adapter<WifiScanResultAdapter.ItemViewHolder> {
    ArrayList<ScanResult> wifiBeans = new ArrayList<>();

    public void refreshWifiData(List<ScanResult> wifis) {
        wifiBeans.clear();
        wifiBeans.addAll(wifis);
        notifyDataSetChanged();
    }

    @Override
    public ItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_wifi_scanresult_item, parent, false);
        return new ItemViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(ItemViewHolder holder, int position) {
        ScanResult scanResult = wifiBeans.get(position);
        holder.mTvWifiSSID.setText(scanResult.SSID);
        holder.mTVWifiCapabilities.setText(scanResult.capabilities);
    }

    @Override
    public int getItemCount() {
        return wifiBeans.size();
    }

    class ItemViewHolder extends RecyclerView.ViewHolder {
        private TextView mTvWifiSSID;
        private TextView mTVWifiCapabilities;
        private TextView mTvTimestamp;

        public ItemViewHolder(View itemView) {
            super(itemView);
            mTvWifiSSID = itemView.findViewById(R.id.item_wifi_ssid);
            mTVWifiCapabilities = itemView.findViewById(R.id.item_wifi_capabilities);
        }
    }
}
